#include "representationPages.h"
#include <iostream>

#define RESAMPLING_MAX 1000

BoundaryFollowingPage::BoundaryFollowingPage(QWidget *parent) : QWidget(parent){
	tryItButton = new QPushButton(tr("Testar"),this);
    connect(tryItButton, SIGNAL(clicked()), this, SLOT(tryIt()));


    QHBoxLayout *buttomLayout = new QHBoxLayout;
	buttomLayout->addWidget(tryItButton, 0, Qt::AlignRight);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(buttomLayout);
	mainLayout->addStretch();

    setLayout(mainLayout);
}

void BoundaryFollowingPage::tryIt(){
    tryItButton->setEnabled(false);
    done();
}

void BoundaryFollowingPage::tryItAgain(){
    tryItButton->setEnabled(true);
}







ChainCodePage::ChainCodePage(QWidget *_parent) : QWidget(_parent){
//    type = 0;
    resample = 20;

//	QLabel* typeLabel = new QLabel(QString::fromUtf8("Vizinhaça:"));
	QLabel* resampleLabel = new QLabel(QString::fromUtf8("Resampling:"));
	QLabel* chainCodeLabel = new QLabel(QString::fromUtf8("Chain code:"));
	QLabel* firstDifferenceLabel = new QLabel(QString::fromUtf8("First Difference:"));
//	QLabel* shapeNumberLabel = new QLabel(QString::fromUtf8("Shape number:"));
//
//    QComboBox *typeComboBox = new QComboBox;
//    typeComboBox->addItem(QString::fromUtf8("4"));
//    typeComboBox->addItem(QString::fromUtf8("8"));
//    connect(typeComboBox, SIGNAL(activated(int)), this, SLOT(changeType(int)));

    QSpinBox *resampleSpinBox = new QSpinBox();
    resampleSpinBox->setRange(2, RESAMPLING_MAX);
    resampleSpinBox->setSingleStep(5);
    resampleSpinBox->setValue(resample);
    connect(resampleSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeResample(int)));


	tryItButton = new QPushButton(tr("Testar"),this);
    connect(tryItButton, SIGNAL(clicked()), this, SLOT(tryIt()));

    chainCodeLineEdit = new QLineEdit();
    chainCodeLineEdit->setReadOnly(true);

    firstDifferenceLineEdit = new QLineEdit();
    firstDifferenceLineEdit->setReadOnly(true);

    shapeNumberLineEdit = new QLineEdit();
    shapeNumberLineEdit->setReadOnly(true);


//
//    QHBoxLayout *typeLayout = new QHBoxLayout;
//    typeLayout->addWidget(typeLabel);
//    typeLayout->addWidget(typeComboBox);
//	typeLayout->addStretch();
    QHBoxLayout *resampleLayout = new QHBoxLayout;
    resampleLayout->addWidget(resampleLabel);
    resampleLayout->addWidget(resampleSpinBox);
	resampleLayout->addStretch();

    QHBoxLayout *chainCodeLayout = new QHBoxLayout;
    chainCodeLayout->addWidget(chainCodeLabel);
    chainCodeLayout->addWidget(chainCodeLineEdit);
	chainCodeLayout->addStretch();

    QHBoxLayout *firstDifferenceLayout = new QHBoxLayout;
    firstDifferenceLayout->addWidget(firstDifferenceLabel);
    firstDifferenceLayout->addWidget(firstDifferenceLineEdit);
	firstDifferenceLayout->addStretch();

//    QHBoxLayout *shapeNumberLineEditLayout = new QHBoxLayout;
//    shapeNumberLineEditLayout->addWidget(shapeNumberLineEditLabel);
//    shapeNumberLineEditLayout->addWidget(shapeNumberLineEditLineEdit);
//	shapeNumberLineEditLayout->addStretch();

    QHBoxLayout *buttomLayout = new QHBoxLayout;
	buttomLayout->addWidget(tryItButton, 0, Qt::AlignRight);

    QVBoxLayout *mainLayout = new QVBoxLayout;
//    mainLayout->addLayout(typeLayout);
    mainLayout->addLayout(resampleLayout);
	mainLayout->addStretch();
    mainLayout->addLayout(chainCodeLayout);
	mainLayout->addStretch();
    mainLayout->addLayout(firstDifferenceLayout);
	mainLayout->addStretch();
//    mainLayout->addLayout(shapeNumberLayout);
//	mainLayout->addStretch();
    mainLayout->addLayout(buttomLayout);
	mainLayout->addStretch();

    setLayout(mainLayout);
}

void ChainCodePage::setStrings(QString _cc, QString _fd, QString _sn){
    chainCodeLineEdit->setText(_cc);
    firstDifferenceLineEdit->setText(_fd);
    shapeNumberLineEdit->setText(_sn);
}

//int ChainCodePage::getType(){
//    return type;
//}

int ChainCodePage::getResample(){
    return resample;
}

//void ChainCodePage::changeType(int _index){
//    type = _index;
//}

void ChainCodePage::changeResample(int _index){
    resample = _index;
}

void ChainCodePage::tryIt(){
    tryItButton->setEnabled(false);
    done();
}

void ChainCodePage::tryItAgain(){
    tryItButton->setEnabled(true);
}







SplittingPage::SplittingPage(QWidget *_parent) : QWidget(_parent){
    depth = 5;

	QLabel* depthLabel = new QLabel(QString::fromUtf8("Profundidade:"));
	QLabel* pointsLabel = new QLabel(QString::fromUtf8("Lista de pontos:"));

    QSpinBox *depthSpinBox = new QSpinBox();
    depthSpinBox->setRange(2, RESAMPLING_MAX);
    depthSpinBox->setSingleStep(5);
    depthSpinBox->setValue(depth);
    connect(depthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeDepth(int)));

    pointsTextEdit = new QTextEdit();
    pointsTextEdit->setReadOnly(true);

	tryItButton = new QPushButton(tr("Testar"),this);
    connect(tryItButton, SIGNAL(clicked()), this, SLOT(tryIt()));

    QHBoxLayout *depthLayout = new QHBoxLayout;
    depthLayout->addWidget(depthLabel);
    depthLayout->addWidget(depthSpinBox);
	depthLayout->addStretch();

    QHBoxLayout *pointsLayout = new QHBoxLayout;
    pointsLayout->addWidget(pointsLabel);
    pointsLayout->addWidget(pointsTextEdit);
	pointsLayout->addStretch();

    QHBoxLayout *buttomLayout = new QHBoxLayout;
	buttomLayout->addWidget(tryItButton, 0, Qt::AlignRight);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(depthLayout);
	mainLayout->addStretch();
    mainLayout->addLayout(pointsLayout);
	mainLayout->addStretch();
    mainLayout->addLayout(buttomLayout);
	mainLayout->addStretch();

    setLayout(mainLayout);
}

void SplittingPage::setPoints(QString _s){
    pointsTextEdit->setText(_s);
}

int SplittingPage::getDepth(){
    return depth;
}

void SplittingPage::changeDepth(int _index){
    depth = _index;
}

void SplittingPage::tryIt(){
    tryItButton->setEnabled(false);
    done();
}

void SplittingPage::tryItAgain(){
    tryItButton->setEnabled(true);
}







BasicDescriptorsPage::BasicDescriptorsPage(QWidget *_parent) : QWidget(_parent){
	QLabel* perimeterLabel = new QLabel(QString::fromUtf8("Petrimetro:"));
	QLabel* areaLabel = new QLabel(QString::fromUtf8("Área:"));
	QLabel* diameterLabel = new QLabel(QString::fromUtf8("Diâmetro:"));
	QLabel* compactnessLabel = new QLabel(QString::fromUtf8("Compactness:"));
	QLabel* circularRatioLabel = new QLabel(QString::fromUtf8("Circular ratio:"));

    perimeterLineEdit = new QLineEdit();
    perimeterLineEdit->setReadOnly(true);
    areaLineEdit = new QLineEdit();
    areaLineEdit->setReadOnly(true);
    diameterLineEdit = new QLineEdit();
    diameterLineEdit->setReadOnly(true);
    compactnessLineEdit = new QLineEdit();
    compactnessLineEdit->setReadOnly(true);
    circularRatioLineEdit = new QLineEdit();
    circularRatioLineEdit->setReadOnly(true);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(perimeterLabel);
    mainLayout->addWidget(perimeterLineEdit);
	mainLayout->addStretch();
    mainLayout->addWidget(areaLabel);
    mainLayout->addWidget(areaLineEdit);
	mainLayout->addStretch();
    mainLayout->addWidget(diameterLabel);
    mainLayout->addWidget(diameterLineEdit);
	mainLayout->addStretch();
    mainLayout->addWidget(compactnessLabel);
    mainLayout->addWidget(compactnessLineEdit);
	mainLayout->addStretch();
    mainLayout->addWidget(circularRatioLabel);
    mainLayout->addWidget(circularRatioLineEdit);
	mainLayout->addStretch();

    setLayout(mainLayout);
}

void BasicDescriptorsPage::setStrings(QString _p, QString _a, QString _d, QString _c, QString _cr){
    perimeterLineEdit->setText(_p);
    areaLineEdit->setText(_a);
    diameterLineEdit->setText(_d);
    compactnessLineEdit->setText(_c);
    circularRatioLineEdit->setText(_cr);
}







MomentInvariantsDescriptorsPage::MomentInvariantsDescriptorsPage(QWidget *_parent) : QWidget(_parent){

	QLabel* invariantMoments1Label = new QLabel(QString::fromUtf8("Momento invariante 1:"));
	QLabel* invariantMoments2Label = new QLabel(QString::fromUtf8("Momento invariante 2:"));
	QLabel* invariantMoments3Label = new QLabel(QString::fromUtf8("Momento invariante 3:"));
	QLabel* invariantMoments4Label = new QLabel(QString::fromUtf8("Momento invariante 4:"));
	QLabel* invariantMoments5Label = new QLabel(QString::fromUtf8("Momento invariante 5:"));
	QLabel* invariantMoments6Label = new QLabel(QString::fromUtf8("Momento invariante 6:"));
	QLabel* invariantMoments7Label = new QLabel(QString::fromUtf8("Momento invariante 7:"));

    invariantMoments1LineEdit = new QLineEdit();
    invariantMoments1LineEdit->setReadOnly(true);
    invariantMoments2LineEdit = new QLineEdit();
    invariantMoments2LineEdit->setReadOnly(true);
    invariantMoments3LineEdit = new QLineEdit();
    invariantMoments3LineEdit->setReadOnly(true);
    invariantMoments4LineEdit = new QLineEdit();
    invariantMoments4LineEdit->setReadOnly(true);
    invariantMoments5LineEdit = new QLineEdit();
    invariantMoments5LineEdit->setReadOnly(true);
    invariantMoments6LineEdit = new QLineEdit();
    invariantMoments6LineEdit->setReadOnly(true);
    invariantMoments7LineEdit = new QLineEdit();
    invariantMoments7LineEdit->setReadOnly(true);

    QHBoxLayout *invariantMoments1Layout = new QHBoxLayout;
    invariantMoments1Layout->addWidget(invariantMoments1Label);
    invariantMoments1Layout->addWidget(invariantMoments1LineEdit);
	invariantMoments1Layout->addStretch();

    QHBoxLayout *invariantMoments2Layout = new QHBoxLayout;
    invariantMoments2Layout->addWidget(invariantMoments2Label);
    invariantMoments2Layout->addWidget(invariantMoments2LineEdit);
	invariantMoments2Layout->addStretch();

    QHBoxLayout *invariantMoments3Layout = new QHBoxLayout;
    invariantMoments3Layout->addWidget(invariantMoments3Label);
    invariantMoments3Layout->addWidget(invariantMoments3LineEdit);
	invariantMoments3Layout->addStretch();

    QHBoxLayout *invariantMoments4Layout = new QHBoxLayout;
    invariantMoments4Layout->addWidget(invariantMoments4Label);
    invariantMoments4Layout->addWidget(invariantMoments4LineEdit);
	invariantMoments4Layout->addStretch();

    QHBoxLayout *invariantMoments5Layout = new QHBoxLayout;
    invariantMoments5Layout->addWidget(invariantMoments5Label);
    invariantMoments5Layout->addWidget(invariantMoments5LineEdit);
	invariantMoments5Layout->addStretch();

    QHBoxLayout *invariantMoments6Layout = new QHBoxLayout;
    invariantMoments6Layout->addWidget(invariantMoments6Label);
    invariantMoments6Layout->addWidget(invariantMoments6LineEdit);
	invariantMoments6Layout->addStretch();

    QHBoxLayout *invariantMoments7Layout = new QHBoxLayout;
    invariantMoments7Layout->addWidget(invariantMoments7Label);
    invariantMoments7Layout->addWidget(invariantMoments7LineEdit);
	invariantMoments7Layout->addStretch();

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(invariantMoments1Layout);
	mainLayout->addStretch();
    mainLayout->addLayout(invariantMoments2Layout);
	mainLayout->addStretch();
    mainLayout->addLayout(invariantMoments3Layout);
	mainLayout->addStretch();
    mainLayout->addLayout(invariantMoments4Layout);
	mainLayout->addStretch();
    mainLayout->addLayout(invariantMoments5Layout);
	mainLayout->addStretch();
    mainLayout->addLayout(invariantMoments6Layout);
	mainLayout->addStretch();
    mainLayout->addLayout(invariantMoments7Layout);
	mainLayout->addStretch();

    setLayout(mainLayout);
}

void MomentInvariantsDescriptorsPage::setStrings(QString _m1, QString _m2, QString _m3, QString _m4, QString _m5, QString _m6, QString _m7){
    invariantMoments1LineEdit->setText(_m1);
    invariantMoments2LineEdit->setText(_m2);
    invariantMoments3LineEdit->setText(_m3);
    invariantMoments4LineEdit->setText(_m4);
    invariantMoments5LineEdit->setText(_m5);
    invariantMoments6LineEdit->setText(_m6);
    invariantMoments7LineEdit->setText(_m7);
}







HistogramDescriptorsPage::HistogramDescriptorsPage(QWidget *_parent) : QWidget(_parent){

	QLabel* meanLabel = new QLabel(QString::fromUtf8("Média:"));
	QLabel* standardDeviationLabel = new QLabel(QString::fromUtf8("Desvio padrão:"));
	QLabel* rLabel = new QLabel(QString::fromUtf8("R(normalizado):"));
	QLabel* thirdMomentLabel = new QLabel(QString::fromUtf8("Terceiro momento:"));
	QLabel* uniformityLabel = new QLabel(QString::fromUtf8("Uniformidade:"));
	QLabel* entropyLabel = new QLabel(QString::fromUtf8("Entropia:"));

    meanLineEdit = new QLineEdit();
    meanLineEdit->setReadOnly(true);
    standardDeviationLineEdit = new QLineEdit();
    standardDeviationLineEdit->setReadOnly(true);
    rLineEdit = new QLineEdit();
    rLineEdit->setReadOnly(true);
    thirdMomentLineEdit = new QLineEdit();
    thirdMomentLineEdit->setReadOnly(true);
    uniformityLineEdit = new QLineEdit();
    uniformityLineEdit->setReadOnly(true);
    entropyLineEdit = new QLineEdit();
    entropyLineEdit->setReadOnly(true);

    QHBoxLayout *meanLayout = new QHBoxLayout;
    meanLayout->addWidget(meanLabel);
    meanLayout->addWidget(meanLineEdit);
	meanLayout->addStretch();

    QHBoxLayout *standardDeviationLayout = new QHBoxLayout;
    standardDeviationLayout->addWidget(standardDeviationLabel);
    standardDeviationLayout->addWidget(standardDeviationLineEdit);
	standardDeviationLayout->addStretch();

    QHBoxLayout *rLayout = new QHBoxLayout;
    rLayout->addWidget(rLabel);
    rLayout->addWidget(rLineEdit);
	rLayout->addStretch();

    QHBoxLayout *thirdMomentLayout = new QHBoxLayout;
    thirdMomentLayout->addWidget(thirdMomentLabel);
    thirdMomentLayout->addWidget(thirdMomentLineEdit);
	thirdMomentLayout->addStretch();

    QHBoxLayout *uniformityLayout = new QHBoxLayout;
    uniformityLayout->addWidget(uniformityLabel);
    uniformityLayout->addWidget(uniformityLineEdit);
	uniformityLayout->addStretch();

    QHBoxLayout *entropyLayout = new QHBoxLayout;
    entropyLayout->addWidget(entropyLabel);
    entropyLayout->addWidget(entropyLineEdit);
	entropyLayout->addStretch();

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(meanLayout);
	mainLayout->addStretch();
    mainLayout->addLayout(standardDeviationLayout);
	mainLayout->addStretch();
    mainLayout->addLayout(rLayout);
	mainLayout->addStretch();
    mainLayout->addLayout(thirdMomentLayout);
	mainLayout->addStretch();
    mainLayout->addLayout(uniformityLayout);
	mainLayout->addStretch();
    mainLayout->addLayout(entropyLayout);
	mainLayout->addStretch();

    setLayout(mainLayout);
}

void HistogramDescriptorsPage::setStrings(QString _m1, QString _m2, QString _m3, QString _m4, QString _m5, QString _m6){
    meanLineEdit->setText(_m1);
    standardDeviationLineEdit->setText(_m2);
    rLineEdit->setText(_m3);
    thirdMomentLineEdit->setText(_m4);
    uniformityLineEdit->setText(_m5);
    entropyLineEdit->setText(_m6);
}

